<?php
declare (strict_types = 1);

namespace app\middleware;
use lizhili\Time;
use think\facade\Db;
class AppInit
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $file=root_path().'tpl/'.'install.txt';
        if(!file_exists($file) and !array_key_exists("/install/index_html", $request->get())  and !array_key_exists("/install/ajax_html", $request->get())){
            $file=root_path().'public/'.'.htaccess';
            file_put_contents($file,'<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>');
            return redirect('/install/index.html');
        }
        return $next($request);
    }
}
